package aio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;

public class AioClient {


    public static void main(String[] args) throws IOException, InterruptedException {
        AsynchronousSocketChannel channel = AsynchronousSocketChannel.open();
        channel.connect(new InetSocketAddress(8888));
        new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(100);
                    System.out.println("write.......");
                    channel.write(ByteBuffer.wrap(Thread.currentThread().getName().getBytes()));
                    Thread.sleep(9900);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }
}
